<%--
  Created by IntelliJ IDEA.
  User: Rui
  Date: 2018/10/26
  Time: 9:41
  To change this template use File | Settings | File Templates.
--%>
<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8" %>
<%
    String path = request.getContextPath();
    String basePath = request.getScheme() + "://" + request.getServerName() + ":" + request.getServerPort() + path + "/";
    String imgSrc = basePath + "resources/images/noImage.jpg";
    session.setAttribute("imgSrc", imgSrc);
%>
<!DOCTYPE html>
<html style="background-color: #fff;">
<head>
    <%@include file="../../../resources/inc/head.jsp" %>
</head>

<body>

<div class="layui-form" lay-filter="layuiadmin-form-contentFriendlyLink" id="layuiadmin-form-contentFriendlyLink"
     style="padding: 20px;">

    <div class="layui-form-item">
        <label class="layui-form-label">名称</label>
        <div class="layui-input-block">
            <input type="hidden" value="${contentCategory.id}" name="id">

            <input type="text" value="${contentCategory.name}" name="name" lay-verify="required" placeholder=""
                   autocomplete="off" class="layui-input">
        </div>
    </div>
<%--    <div class="layui-form-item">--%>
<%--        <label class="layui-form-label">所属上级</label>--%>
<%--        <div class="layui-input-block">--%>
<%--            <select name="pid">--%>
<%--                <option value="">无</option>--%>
<%--            </select>--%>
<%--        </div>--%>
<%--    </div>--%>
    <div class="layui-form-item">
        <label class="layui-form-label">类型</label>
        <div class="layui-input-block">
            <select name="type">
                <option value="1"${contentCategory.type=='1'?'selected':''} >文章</option>
                <option value="2" ${contentCategory.type=='2'?'selected':''}> 客户</option>
                <option value="3" ${contentCategory.type=='3'?'selected':''}>解决方案</option>
                <option value="4" ${contentCategory.type=='4'?'selected':''}> 软件技术与服务</option>
                <%--<c:forTokens items="文章" delims="," var="type" varStatus="typeStatus">--%>
                    <%--<option value="${(typeStatus.index+1)}" ${contentCategory.type==(typeStatus.index+1)?'selected':''}>--%>
                            <%--${type}--%>
                    <%--</option>--%>
                <%--</c:forTokens>?--%>
            </select>
        </div>
    </div>


    </div>






    <div class="layui-form-item layui-hide">
        <input type="button" lay-submit lay-filter="LAY-submit" id="LAY-submit" value="确认">
    </div>

</div>
<%@include file="../../../resources/inc/footer.jsp" %>

<script>
    layui.config({
        base: '<%=basePath%>resources/lib/layuiAdmin/' //静态资源所在路径
    }).extend({
        index: 'lib/index' //主入口模块
    }).use(['layedit', 'index', 'form', 'upload'], function () {
        var $ = layui.$
            , form = layui.form
            , upload = layui.upload,
            layedit = layui.layedit;
    });


    function createSubmit() {
        var layer=layui.layer;
        var submitID = 'LAY-submit';
        layui.form.on('submit('+ submitID +')', function(data){
            var formData = data.field;
            if(formData.id==null||formData.id==""){
                formData.id = null;
                $.ajax({
                    url:"<%=basePath%>manager/content/category/create.action",
                    type:"POST",
                    data:formData,
                    dataType:"JSON",
                    success:function (data) {
                        layer.closeAll('loading');
                        if(data.success){
                            layer.msg("创建成功,1秒后跳转")
                            setTimeout(function () {
                                window.parent.location.reload(); //刷新父页面
                                var index = parent.layer.getFrameIndex(window.name); //获取窗口索引
                                parent.layer.close(index);
                            },1000);
                        }else{
                            layer.msg(data.msg, {icon: 5});
                        }
                    }
                });
            }else{

                $.ajax({
                    url: "<%=basePath%>manager/content/category/update.action",
                    type:"POST",
                    data:formData,
                    dataType:"JSON",
                    success:function (data) {
                        layer.closeAll('loading');
                        if(data.success){
                            layer.msg("修改成功,1秒后跳转")
                            setTimeout(function () {
                                window.parent.location.reload(); //刷新父页面
                                var index = parent.layer.getFrameIndex(window.name); //获取窗口索引
                                parent.layer.close(index);
                            },1000);
                        }else{
                            layer.msg(data.msg, {icon: 5});
                        }
                    }
                });
            }
        })
        $("#"+submitID).trigger('click');
    }
</script>
</body>
</html>
